package com.foryou.swkj.core.util;


import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by Administrator on 2017/5/31.
 */
public class BeanFactory {

    private static final ConcurrentHashMap currentMap = new ConcurrentHashMap();

    static{
        try {
            currentMap.put(GenerateVerifyCodeServlet.class.getSimpleName(), createBean(GenerateVerifyCodeServlet.class));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public static <T> T createBean(Class<T> clazz) throws Exception {
        if(currentMap.containsKey(clazz.getSimpleName())){
            return (T)currentMap.get(clazz.getSimpleName());
        }
        T t = clazz.newInstance();
        return t;
    }

}
